<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 流年 <liu21st@gmail.com>
// +----------------------------------------------------------------------

// 应用公共文件
/**
 * 写日志
 * * @param $data : 数据
 * * @param $fileName : 写入哪个日志
 */
function logs($data = null, $fileName = null)
{
    if (is_null($data) || is_null($fileName)) {
        $out_arr['code'] = '400004';
        return $out_arr;
    }
    $path = RUNTIME_PATH . 'log/' . $fileName;
    if (!is_dir($path)) {
        $mkdir_re = mkdir($path, 0777, TRUE);
        if (!$mkdir_re) {
            $this->logs($data, $fileName);
        }
    }
    $filePath = $path . "/" . date("Y-m-d", time());
    $time = date("Y-m-d H:i:s", time());
    $re = file_put_contents($filePath, $time . " " . var_export($data, TRUE) . "\r\n\r\n", FILE_APPEND);
    if (!$re) {
        $this->logs($data, $fileName);
    } else {
        $out_arr['code'] = '000000';
        return $out_arr;
    }
}

